package de.urwalking.legobaukasten;

import java.util.ArrayList;

public class URWleveledge extends URWedge
{
	int sourceLevel;
	int sinkLevel;
	String type;
	
	public URWleveledge(int id, URWnode source, URWnode sink, String type)
	{
		super(id, source, sink);
		this.type = type;
	}
	
	public URWleveledge(int id, int sourceId, int sinkId, int sourceLevel, int sinkLevel, String type)
	{
		super(id, sourceId, sinkId);
		this.sourceLevel = sourceLevel - 1;
		this.sinkLevel = sinkLevel - 1;
		this.type = type;
	}
	
	public boolean initLevelEdge(ArrayList<ArrayList<URWnode>> list)
	{
		if(source == null)
		{
			for(int i = 0; i < list.size(); i++)
			{
				for(URWnode node : list.get(i))
				{
					if(node.id == sourceId && sourceLevel == i)
					{
						source = node;
						break;
					}
				}
			}
		}
		
		if(sink == null)
		{
			for(int i = 0; i < list.size(); i++)
			{
				for(URWnode node : list.get(i))
				{
					if(node.id == sinkId && sinkLevel == i)
					{
						sink = node;
						break;
					}
				}
			}
		}
		
		if(source != null && sink != null) {
			initialized = true;
			return true;
		}
		else return false;
	}
}
